//
//  ShippingAddressController.m
//  HaoHaiSpell
//
//  Created by 郭健 on 16/6/17.
//  Copyright © 2016年 海城. All rights reserved.
//

#import "ShippingAddressController.h"

#import "ShowCell.h"

#import "AddressController.h"


@interface ShippingAddressController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tableView;

@end

@implementation ShippingAddressController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    [self setUpShippingAddressTableView];
    [self setUpTabBar];
    
    
    //接收通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nameAction:) name:@"name" object:nil];
    

}

-(void)nameAction:(NSNotification *)sender{

    ShowCell *showCell = [[ShowCell alloc]init];
    
    showCell.nameLabel.text = sender.userInfo[@"key"];
    
}

-(void)dealloc{

    [[NSNotificationCenter defaultCenter] removeObserver:self];
}




-(void)setUpShippingAddressTableView{

    _tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    
    //注册cell
    [_tableView registerNib:[UINib nibWithNibName:@"ShowCell" bundle:nil] forCellReuseIdentifier:@"ShowCell"];
    
    [self.view addSubview:_tableView];
    
}


-(void)setUpTabBar{

    UIButton *tabBarBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    tabBarBtn.backgroundColor = HWColor(0.95*255, 0.66*255, 0.21*255);
    
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGFloat height = [UIScreen mainScreen].bounds.size.height - 44;
    
    tabBarBtn.frame = CGRectMake(0, height, width , 44);

    [tabBarBtn setTitle:@"添加收货地址" forState:UIControlStateNormal];
    [tabBarBtn addTarget:self action:@selector(addAddress) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:tabBarBtn];
    
    
}

-(void)addAddress{

    
    AddressController *addressVC = [[AddressController alloc]init];
    [self.navigationController pushViewController:addressVC animated:YES];
    

}





#pragma mark -- UITableView 的代理方法
//-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//
//    return 2;
//}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    ShowCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShowCell" forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor grayColor];
    return cell;
    
}

//cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 130;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    NSLog(@"收货地址");

    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
